package com.kvest.map.mapview;

import android.content.Context;
import android.opengl.GLSurfaceView;
import com.kvest.map.mapview.engine.controller.MapController;
import com.kvest.map.mapview.engine.model.AbstractModel;
import com.kvest.map.mapview.engine.model.OSMModel;
import com.kvest.map.mapview.engine.model.TileTextureManager;
import com.kvest.map.mapview.engine.renderer.OSMMapRenderer;

/**
 * Created with IntelliJ IDEA.
 * User: Kvest
 * Date: 21.04.13
 * Time: 14:44
 * To change this template use File | Settings | File Templates.
 */
public class OSMMapView extends GLSurfaceView {


    private OSMMapRenderer renderer;
    private AbstractModel model;

    public OSMMapView(Context context) {
        super(context);

        //Initialize TileTextureManager
        TileTextureManager.getInstance().setContext(context);

        //Create model and renderer
        model = initModel();
        renderer = new OSMMapRenderer(model);
        renderer.setOnSurfaceActionListener(model);
        setRenderer(renderer);

        //Create controller
        MapController controller = new MapController(this, model);

        //Set renderer mode
        //setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
        setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
    }

    private AbstractModel initModel() {
        AbstractModel osmModel = new OSMModel();
        return osmModel;
    }

    public int getBackgroundColor() {
        return renderer.getBackgroundColor();
    }

    public void setBackgroundColor(int backgroundColor) {
        renderer.setBackgroundColor(backgroundColor);
    }
}
